node{
    def sn = "${service_name}"
    def registryBase = '106.14.141.132:80/sidecar'
    def hookMap = [
        'service-dict':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=XtRkP4Qa7nUSupuRVoS6gN5z6m3bdzWJDkx3YOJI\\&projectId=1a5',
        'service-order':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=4ftJb2Oi73KX8fQgQZJvHKSLkJ9jnCbI2tJH80H5\\&projectId=1a5',
        'service-product':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=MfBGAFVj1XT0aEkQ8bcWvC5smOjwv06fWTvsfBzN\\&projectId=1a5',
        'service-schedule':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=IAW4W9MnDhrbgHQPIjUj0hwWSPsi9iR3KfCdGkva\\&projectId=1a5',
        'service-station':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=PkJHjJUHUWi3PbCCGZfco0jnbVsjt9YmBshcBLjM\\&projectId=1a5',
        'service-user':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=JstjyKeC9mh1OMkjkhxgtZi5dSqS13gGQYWU7H2O\\&projectId=1a5',
        'server-gateway':'http://rancher.lance-c.vip/v1-webhooks/endpoint?key=N1odSeE0pvaQj8VnmkiEyZ1BuLCw8DjF7UPfYc2o\\&projectId=1a5'
    ]
    stage('clean workspace') {
        cleanWs()
    }
    
    stage('execute hook') {
        String hookAddr = hookMap[sn]
        if (hookAddr == null) {
            println("can not found hook configurations ${sn}")
            sh 'exit 1'
        } else {
            sh """
                resp=`curl -l -H "Content-type: application/json" -X POST -d '{"push_data": {"tag": "latest"},"repository": {"repo_name": "${registryBase}/${sn}"}}' ${hookAddr}`
                echo \$resp
            """
            println("service named ${sn} has redeployed on server successfully. ")
        }
    }
}